<?php

namespace app\index\controller;

use think\Controller;
use think\Session;
use think\Db;

class Content extends Controller
{
    public function content()
    {

//        halt(1111);
        $uid = Session::get('id');
        if (empty($uid)){
            return $data = false;
        }
//        halt($uid);
        $data = request()->post();
//        halt($data);
        $data['time']= date('Y-m-d H:i:s');
        $data['uid'] = $uid;
//        halt($data);
        $mid = db()->table('wb_comments')->insertGetId($data);
        if ($mid){
            $arr = Db::field('*')
                ->table(['wb_message'])
                ->where('id = '.$data['mid'])
                ->find();
            $arr['commentnum'] = $arr['commentnum']+1;

            $result =  Db::table('wb_message')->where('id', $data['mid'])->update($arr);
        }

        $this->success('发表成功');

    }

    public function conten()
    {

       // halt(1111);
        $uid = Session::get('id');
        if (empty($uid)){
            return $data = false;
        }
//        halt($uid);
        $data = request()->post();
//        halt($data);
        $data['time']= date('Y-m-d H:i:s');
        $data['uid'] = $uid;
//        halt($data);
        $mid = db()->table('wb_comments')->insertGetId($data);
        if ($mid){
            $arr = Db::field('*')
                ->table(['wb_message'])
                ->where('id = '.$data['mid'])
                ->find();
            $arr['commentnum'] = $arr['commentnum']+1;

            $result =  Db::table('wb_message')->where('id', $data['mid'])->update($arr);
        }

        return $arr['commentnum'];

    }



}
